1. Field of the Invention
This invention relates generally to the field of computer programming. More particularly, the invention relates to a system and method for transforming object-oriented program code.
2. Description of the Related Art
Java is an object-oriented programming language which is used to design computer programs which are platform-independent. That is, the same Java object code may be used on numerous different operating systems including, for example, Windows 95, Unix, Solaris, and the Macintosh OS. This interoperability makes Java an ideal choice for programming Internet applications.
Once a program is written in Java source code, the Java compiler generates a compact, architecture-neutral object code (commonly referred to as known as Java bytecode) which may be executed by a runtime interpreter residing on the client computer. This runtime interpreter is commonly referred to as a Java “virtual machine.” The Java virtual machine interprets the object code so that the instructions may be executed by the client's native microprocessor. Virtual machines are included in commonly available Internet browser applications such as Netscape Navigator™ or Microsoft Internet Explorer.™
Java was derived from the popular C++ programming language and retained many significant features of that language. For example, Java, like C++, is object-oriented. Accordingly, Java programs are developed around “classes” and “objects.” These two terms are not interchangeable but they are directly related to one another. A class can be thought of as a template or blueprint from which an object is made. An object may contain some number of “fields” in which data (such as integers, strings of characters, or references to other objects) may be stored. A class defines a number of actions (“methods”) which may operate on the object and are either implemented in bytecode, linked to native code, or abstract. Every object is an “instance” of some specific class—containing the described fields an may be operated upon by the described methods.
A “class file” is a binary object that describes a single class—all the fields, methods, object code of those methods, etc. The format of class files is described in detail by chapter four of “The Java Virtual Machine Specification” (ISBN 0-201-43294-3). The basic layout of a class file shall be described below.
Programmers typically combine groups of ready-made class files, referred to as “class libraries,” for writing programs. For example, a class library is typically available for providing graphical user interface (“GUI”) functions such as windowing routines, buttons, scroll bars and other graphical features.
As illustrated in FIG. 1, an exemplary class file 100 is comprised of a header 101, a plurality of constant pool entries 102, and one or more methods 103-105 and/or fields 106, 107. The header 101 contains data for identifying a class file as a class file (e.g., the revision information). The constant pool entries 102 are each comprised of a header portion (a single byte “tag”) 111, 121, 131, 141, and a variable length data portion 113, 123, 133, 143, respectively. The header portion 111, 121, 131, 141 indicates the type of constant pool entry. According to the specification, entries may be of the type Class, FieldRef, Methodref, InterfaceMethodref, String, Integer, Float, Long, Double, NameAndType, or Utf8. The data portion 113, 123, 133, 143 contains the actual constant pool information associated with the entry. The Utf8, Integer, Float, Long, and Double types encapsulate simple constant data as implied by their names. The other types contain references (by one-based index) to other entries. For example, a Methodref refers to a Class entry and a NameAndType entry, identifying a specific method of a specific class.
For example, as illustrated in FIG. 2, class files 200, 210 and 220 each contain constant pool entries which refer to methods and fields provided by class file 230. More specifically, class files 200, 210 and 220 include “MethodRef Foo” entries 203, 213 and 223, respectively, in their constant pools 202, 212, and 222 which refer to the method Foo 236 of class 230. In addition, class file 230 itself includes a “MethodRef Foo” entry in its constant pool 232 which refers to method Foo 236. Similarly, the constant pools of class files 200, 220 and 230 each include a “FieldRef Bar” entry which refer to field Bar 238 in class file 230.
Accordingly, when each of the foregoing class files are used in a program (e.g., a Java applet or application), three redundant constant pool entries referring to field Bar 238 are loaded into memory (i.e., FieldRef entries 240, 241, and 242) and four redundant constant pool entries referring to method Foo 236 are loaded into memory (i.e., MethodRef entries 203, 213, 223, 233). Considering the fact that a program may utilize scores of class files and that each class file may contain hundreds, or even thousands, of constant pool entries, a significant amount of memory may be consumed by redundant information.
Accordingly, what is needed is a system and method for reducing the memory requirements for object-oriented programs.